<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0 text-dark">邮件内容</h1>
            </div><!-- /.col -->
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a th:href="@{admin}">首页</a></li>
                    <li class="breadcrumb-item active">邮件</li>
                    <li class="breadcrumb-item active">阅读</li>
                </ol>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.container-fluid -->
</div>
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="row">
<!--            <div class="col-md-3">-->

<!--                -->
<!--            </div>-->
            <!-- /.col -->
            <div class="col-md-9 m-auto">
                <a href="#mailbox/normal" class="btn btn-primary btn-block mb-3">返回邮箱</a>
                <div class="card card-primary card-outline">
                    <div class="card-header">
                        <h3 class="card-title">邮件内容：</h3>

                        <div class="card-tools">
                            <a href="#" class="btn btn-tool" title="Previous"><i class="fas fa-chevron-left"></i></a>
                            <a href="#" class="btn btn-tool" title="Next"><i class="fas fa-chevron-right"></i></a>
                        </div>
                    </div>
                    <!-- /.card-header -->
                    <div class="card-body p-0">
                        <div hidden="hidden" class="hide">
                            <input id="email_id" name="email_id" th:value="${email?.getId()}">
                            <input id="email_mark" th:value="${email?.getMark()}">
                        </div>
                        <div class="mailbox-read-info">
                            <h5>主题 : <span th:text="${email?.getTitle()}"></span></h5>
                            <h6>From: <span th:text="${email?.getPostAddress()}">邮件来源</span>
                                <span class="mailbox-read-time float-right" th:text="${email?.getCreateTime()}">15 Feb. 2015 11:03 PM</span></h6>
                        </div>
                        <!-- /.mailbox-read-info -->
                        <div class="mailbox-controls with-border text-center">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default btn-sm" data-container="body" title="Delete">
                                    <i class="far fa-trash-alt"></i>
                                </button>
                                <button type="button" class="btn btn-default btn-sm" data-container="body" title="Reply">
                                    <i class="fas fa-reply"></i>
                                </button>
                                <button type="button" class="btn btn-default btn-sm" data-container="body" title="Forward">
                                    <i class="fas fa-share"></i>
                                </button>
                            </div>
                            <!-- /.btn-group -->
                            <button type="button" class="btn btn-default btn-sm" title="Print">
                                <i class="fas fa-print"></i>
                            </button>
                        </div>
                        <!-- /.mailbox-controls -->
                        <div class="mailbox-read-message">
                            <div th:utext="${email?.getContent()}">邮件内容</div>
                        </div>
                        <!-- /.mailbox-read-message -->
                    </div>
                    <!-- /.card-body -->
<!--                    这是附件所在的标签-->
                    <div class="card-footer bg-white">
                        <ul class="mailbox-attachments d-flex align-items-stretch clearfix">
                            <li th:if="${email?.getFile()!=null}">
                                <span class="mailbox-attachment-icon"><i class="far fa-file-pdf"></i></span>

                                <div class="mailbox-attachment-info">
                                    <a th:href="${email?.getFile()}" target="_blank" class="mailbox-attachment-name"><i class="fas fa-paperclip mr-1"></i>
<!--                                        截取文件路径，并将七牛云的url剔除，只留下文件名-->
                                        <span th:text="${#strings.replace(email?.getFile(),'http://rewgjkhsm.hn-bkt.clouddn.com/','') }">邮件名称</span>
                                    </a>
                                    <span class="mailbox-attachment-size clearfix mt-1">
<!--                                        <span>1,245 KB</span>-->
                                        <a th:href="${email?.getFile()}" target="_blank" class="btn btn-default btn-sm float-right"><i class="fas fa-cloud-download-alt"></i></a>
                                    </span>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <!-- /.card-footer -->
                    </form>
                    <div class="card-footer">
                        <div class="float-right">
                            <button type="button" class="btn btn-default"><i class="fas fa-reply"></i> 回复</button>
                            <button type="button" class="btn btn-default"><i class="fas fa-share"></i> 下一条</button>
                        </div>
                        <button onclick="deleteEmail();" type="button" class="btn btn-default"><i class="far fa-trash-alt"></i> 删除</button>
                        <button type="button" class="btn btn-default"><i class="fas fa-print"></i> 打印</button>
                    </div>
                    <!-- /.card-footer -->
                </div>
                <!-- /.card -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </div><!-- /.container-fluid -->
</section>
<!-- /.content -->

<script>
    function deleteOneEmail(){
        let email_id = $('#email_id').text();
        $.ajax({
            url: '/mailbox/deleteOne/',
            data: {id:email_id},
            method: 'GET',
            success: function(data){

            }
        })
    }
    /*删除*/
    function deleteEmail() {
        let email_id = $('#email_id').val();
        let email_mark = $('#email_mark').val();
        // console.log("准备删除："+email_id);
        Core.confirm("确定删除该邮件？", function () {
            Core.postAjax("/mailbox/deleteOne", {"email_id": email_id}, function (data) {
                if (data.status === 200) {
                    setTimeout(function () {
                        // console.log("延迟0.5秒触发");
                        let flag = Number.parseInt(email_mark);
                        if(flag===0)
                            $(window).attr('location','/admin#mailbox/normal');
                        else if(flag===1)
                            $(window).attr('location','/admin#mailbox/spam');
                    },500); //1秒后执行函数，只执行一次。
                }
                layer.msg(data.msg);
            })
        })
    }

    function refreshTable() {
        Core.refreshTable("#table")
    }

    /*查询参数*/
    function queryParams(params) {
        return {
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
            keywords: $("#keywords").val(),
            categoryId: $("#categoryId").val(),
            status: $("#status").val(),
        };
    }

    /*编辑*/
    function editArticle(id) {
        window.location.href = "#article/edit?id=" + id
    }

    /*删除*/
    function deleteArticle(id) {
        Core.confirm("确定删除该分类？", function () {
            Core.postAjax("/article/delete", {"id": id}, function (data) {
                if (data.status === 200) {
                    refreshTable();
                }
                layer.msg(data.msg);
            })
        })
    }


    function previewImg(src) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: '45%',
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: '<img style="width: 100%" alt="link" src="' + src + '">'
        });
    }

</script>